/* @(#)GSServerListener.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-2-27     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.integration;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

import com.hitrust.gs.integration.socket.GSMultiThreadServerSoket;
import com.hitrust.gs.integration.socket.GSServerThread;
import com.hitrust.gs.lib.GSBaseConstants;

/**
 * 
 */
public class GSServerListener extends Thread {
    /**
     * 端口
     */
    private int iPort;
    
    private ServerSocket iSvrSocket;
    
    
    private static GSServerListener iGSServerListener = null; 
    
    public static ArrayList APEP_TO_BUS_CONTENTS = new ArrayList();
    
    public GSServerListener(int aPort){
        iPort = aPort;
        try{
            iSvrSocket = new ServerSocket(iPort);
            //start();    
        }catch(Exception e){
            e.printStackTrace();
        }

    }
    public void run(){
        Socket request = null;
        Thread receiveThread = null;
        try{
            while(true){
                if(GSBaseConstants.SOCKET_SERVICE_FLAG.equals("0")){
                    break;
                }
                request = iSvrSocket.accept();
                receiveThread = new GSServerThread(request);
                //启动mpsServerThread线程
                receiveThread.start();
                
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public static final synchronized GSServerListener getInstance(int aPort){
        if(iGSServerListener == null){
            iGSServerListener = new GSServerListener(aPort);
        }
        return iGSServerListener;
    }
}
